package rs.networx.entity;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.EAGER;
import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="posts")
public class Post implements java.io.Serializable {

	private static final long serialVersionUID = -2054872016L;

	@Id
	@GeneratedValue(strategy=IDENTITY)	
	@Column(name="post_id", unique=true, nullable=false)
	private Integer id;

	@Column(name="title", unique=false, nullable=false)
	private String title;

	@Column(name="date", unique=false, nullable=false)
	private java.util.Date date;

	@Column(name="text", unique=false, nullable=false)
	private String text;

	@Column(name="content", unique=false, nullable=false)
	private String content;
	
	@Column(name="type", unique=false, nullable=false)
	private Integer type;
	
	@OneToMany(cascade={ALL}, fetch=EAGER, mappedBy = "post")
	private Set<Comment> comments = new HashSet<Comment>();

	@ManyToOne
	@JoinColumn(name="owner_id", referencedColumnName="person_id", nullable=false)
	private Person owner;
	
	@ManyToOne
	@JoinColumn(name="poster_id", referencedColumnName="person_id", nullable=false)
	private Person poster;

	public Post() {
	}

	public String getTitle() {
		return title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public java.util.Date getDate() {
		return date;
	}

	public void setDate(java.util.Date date) {
		this.date = date;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public java.util.Set<Comment> getComments() {
		return comments;
	}

	public void setComments(java.util.Set<Comment> comment) {
		this.comments = comment;
	}

	public Person getOwner() {
		return owner;
	}

	public void setOwner(Person owner) {
		this.owner = owner;
	}

	public Person getPoster() {
		return poster;
	}

	public void setPoster(Person poster) {
		this.poster = poster;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public Integer getId() {
		return id;
	}

	public String toString() {
		return "Post" + " id=" + id + " title=" + title + " date=" + date
		+ " text=" + text + " type=" + type + " content=" + content;
	}

}